package com.example.week10_advanceui2;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;

public abstract class NewsActivity extends AppCompatActivity implements
        NewsListFragment.OnNewsSelectedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
    }

    /*public void onPointerCaptureChanged(boolean hasCapture)
    {
        super.onPointerCaptureChanged(hasCapture);
    }*/


    public void onNewsSelected(Bundle bundle) {
        FragmentManager manager=getSupportFragmentManager();

        Fragment detailFragment=manager.findFragmentById(R.id.fragment_detail);

        if(detailFragment!=null)
        {
            NewsDetailFragment newsDetailFragment=(NewsDetailFragment) detailFragment;
            newsDetailFragment.setNews(bundle.getInt("position",0));
        }
        else
        {
            Intent intent=new Intent(this,NewsDetailActivity.class);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }
}
